package de.webtech.faceplace.components;

import java.util.Iterator;
import java.util.LinkedList;


import org.apache.tapestry5.*;
import org.apache.tapestry5.annotations.*;
import org.apache.tapestry5.ioc.annotations.*;
import org.apache.tapestry5.services.Request;
import org.apache.tapestry5.BindingConstants;
import org.apache.tapestry5.SymbolConstants;

/**
 * Layout component for pages of application faceplace.
 */
@Import(stylesheet = "context:layout/welcomeLayout.css")
public class WelcomeLayout
{
    /**
     * The page title, for the <title> element and the <h1> element.
     */
    @Property
    @Parameter(required = true, defaultPrefix = BindingConstants.LITERAL)
    private String title;

    @Property
    private String pageName;

    @Property
    @Parameter(defaultPrefix = BindingConstants.LITERAL)
    private String sidebarTitle;

    @Property
    @Parameter(defaultPrefix = BindingConstants.LITERAL)
    private Block sidebar;

    @Inject
    private ComponentResources resources;
    
    @Inject
    private Request request;

    @Property
    @Inject
    @Symbol(SymbolConstants.APPLICATION_VERSION)
    private String appVersion;
    
    public String getClassForPageName()
    {
        return resources.getPageName().equalsIgnoreCase(pageName)
                ? "current_page_item"
                : null;
    }

    public String[] getPageNames()
    {
    	LinkedList<String> l = new LinkedList<String>();
 
    	if (request.getSession(true).getAttribute("user")==null){
    		l.add("Welcome");
    		l.add("Registry");
    	} else {
    		l.add("Index");
    	}
    	l.add("About");
    	l.add("Contact");
    	String[] arr = new String[l.size()];
    	int i=0;
    	Iterator<String> iter = l.iterator();
    	while(iter.hasNext()){
    		arr[i++]=iter.next();
    	}
        return arr;
    }
}
